<template>
	<view>
		<u-navbar @leftClick='leftClickShow()'>
			<view slot="left">
				<view class="nav-content">
					<text class="selected-text">{{ building }}</text>
					<u-icon name="arrow-down"></u-icon>
				</view>
			</view>
		</u-navbar>
		<u-picker :show="show" @close="()=>show=false" @cancel="()=>show=false" :columns="columns" @confirm="confirm"
			title="选择项目" keyName="floorName"></u-picker>
		<view class="all">
			<view class="container">
				<view class="pix-container" @click="goto('/mainpkg/public_zone_detail/public_zone_detail')">
					<view class="tip">
						<text class="title">公建芯造</text>
						<text class="area">建筑面积：{{publicArea}} m&sup2</text>
					</view>

					<image :src="getSrc('hnnzkwfopvdpqsnpegzixwppsiopdrpvmourssbiyynzxelodrxvsuiyzhtosafm')" class="pix"></image>
				</view>
				<view class="pix-container" @click="goto('/mainpkg/house_building/house_building')">
					<view class="tip">
						<text class="title">房屋芯造</text>
						<text class="area">建筑面积：{{privateArea}} m&sup2</text>
					</view>
					<image :src="getSrc('uqezcgvwvoaiaxgldkxegbknufgqwqwperiqpkmvrqzhyvkgmsepxoqhgrxbayiw')" class="pix"></image>
				</view>
			</view>
			<!-- 底部关注卡 -->
			<view class="follow">
				<follow-me></follow-me>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getUserInfo()
			// this.userId = uni.getStorageSync('userId')
			this.getEstate()
		},
		data() {
			return {
				show: false,
				columns: [],
				building: '',
				userId: '',
				publicArea: "",
				privateArea: ''
			};
		},
		methods: {
			getSrc(id) {
				if ((typeof id) != undefined && id != null && id != '') {
					let _src = uni.$http.baseURL + '/file/download?fileId=' + id
					return _src
				}
			},
			leftClickShow() {
				this.getEstateColums()
				this.show = true
			},
			async getEstateColums() {
				const {
					data
				} = await uni.$http.post(uni.$http.baseURL + '/userEstateMap/getByQuery', {
					estateType: 2,
					roleId: "3",
					userId: uni.getStorageSync('userId')
				})
				if (data.status == 0) {
					let _t = []
					for (let i = 0; i < data.body.length; i++) {
						_t.push(data.body[i].businessRealEstateVO)
					}
					this.columns = [_t]
				} else {
					uni.$showMsg(data.message)
				}

			},
			//获取绑定的楼盘信息
			async getEstate() {
				const {
					data
				} = await uni.$http.post(uni.$http.baseURL + '/userEstateMap/getByQuery', {
					estateType: 2,
					roleId: "3",
					userId: uni.getStorageSync('userId')
				})
				if (data.status == 0) {
					if (data.body.length != 0) {
						let _t = []
						for (let i = 0; i < data.body.length; i++) {
							_t.push(data.body[i].businessRealEstateVO)
						}
						this.building = _t[0].floorName
						uni.setStorageSync("selectedEstate", this.building)
						this.publicArea = _t[0].sellInfo.constructionArea
						this.privateArea = _t[0].sellInfo.floorSpace
						uni.setStorageSync("estateId", _t[0].floorId)
						this.columns = [_t]
					} else {
						this.building = '暂无数据'
					}

				} else {
					uni.$showMsg(data.message)
				}

			},
			confirm(e) {
				console.log('confirm', e);
				this.building = e.value[0].floorName
				uni.setStorageSync("selectedEstate", this.building)
				uni.setStorageSync("estateId", e.value[0].floorId)
				this.publicArea = e.value[0].sellInfo.constructionArea
				this.show = false
			},
			async getUserInfo() {
				const {
					data: res
				} = await uni.$http.get(uni.$http.baseURL + '/user/getUserInfo')
				if (res.message === '成功') {
					// this.userInfo = res.body
					uni.setStorageSync('avator', res.body.headerUrl)
					uni.setStorageSync('phone', res.body.phone)
					uni.setStorageSync('userId', res.body.userId)
					uni.setStorageSync('userName', res.body.userName)
					uni.setStorageSync('roleId', res.body.roleId)
					let initData = {
						fromId: res.body.userId,
						isCreateConnect: true
					}
					this.$Socket.send(JSON.stringify(initData));
					this.getEstate()
					console.log("获取用户信息成功")
				}

			},
			goto(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.left {
		.building {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			width: 160rpx;
			margin-left: 4rpx;
		}
	}

	.all {
		display: flex;
		flex-direction: column;
		padding: 30rpx;

		.container {
			margin-top: 160rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-around;

			.pix-container {
				.tip {
					position: absolute;
					display: flex;
					flex-direction: column;
					color: #FFFFFF;
					margin-top: 75rpx;
					margin-left: 30rpx;

					.title {
						font-size: 48rpx;
						font-weight: bold;
					}

					.area {
						margin-top: 20rpx;
						font-size: 24rpx;
						font-weight: 500;
					}
				}

				.pix {
					width: 335rpx;
					height: 260rpx;
				}
			}
		}

		.follow {
			position: absolute;
			bottom: 20rpx;
			// width: 720rpx;
			height: 200rpx;
			margin-bottom: 10rpx;
		}
	}

	.nav-content {
		display: inline-flex;
		flex-direction: row;
	}
</style>
